package main

import (
	"encoding/json"
	"fmt"
)

type Person struct {
	Name   string `json:"name"`
	Age    int    `json:"age"`
	Gender string `json:"gender,omitempty"`
}

func main() {
	// 创建一个 Person 对象
	person := Person{Name: "Alice", Age: 25, Gender: "11"}

	// 将 Person 对象序列化为 JSON 字符串
	data, err := json.Marshal(person)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(data)) // 输出: {"name":"Alice","age":25}

	// 将 JSON 字符串反序列化为 Person 对象
	data1 := `{"name":"Alice","age":25,"gender":"11"}`
	var p Person
	err = json.Unmarshal([]byte(data1), &p)
	if err != nil {
		panic(err)
	}
	fmt.Println(p) // 输出: {Alice 25 ""}

	person1 := "czc"
	data2, err1 := json.Marshal(person1)
	if err1 != nil {
		fmt.Println(err1)
	}
	fmt.Println(data2)

}
